﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Core.Entities.Stock;

namespace Infrastructure.Data.Configurations.SM
{
    /// <summary>
    /// 入库记录配置
    /// </summary>
    public class StockInConfiguration : IEntityTypeConfiguration<StockIn>
    {
        public void Configure(EntityTypeBuilder<StockIn> builder)
        {
            // 设置表名
            builder.ToTable("SM_Stock_In");

            // 配置主键
            builder.HasKey(s => s.Id);

            // 属性配置
            builder.Property(s => s.Id)
                .HasColumnName("ID")
                .HasMaxLength(50);

            builder.Property(s => s.MaterCode)
                .HasColumnName("MaterCode")
                .HasMaxLength(255);

            builder.Property(s => s.MaterName)
                .HasColumnName("MaterName")
                .HasMaxLength(255);

            builder.Property(s => s.MaterType)
                .HasColumnName("MaterType")
                .HasMaxLength(20);

            builder.Property(s => s.WarehouseID)
                .HasColumnName("WarehouseID")
                .HasMaxLength(255);

            builder.Property(s => s.WarehouseName)
                .HasColumnName("WarehouseName")
                .HasMaxLength(255);

            builder.Property(s => s.LocationID)
                .HasColumnName("LocationID")
                .HasMaxLength(50);

            builder.Property(s => s.LocationName)
                .HasColumnName("LocationName")
                .HasMaxLength(50);

            builder.Property(s => s.Unit)
                .HasColumnName("Unit")
                .HasMaxLength(255);

            builder.Property(s => s.In_Quantity)
                .HasColumnName("In_Quantity")
                .HasColumnType("decimal(18, 2)");

            builder.Property(s => s.In_Time)
                .HasColumnName("In_Time");

            builder.Property(s => s.In_Type)
                .HasColumnName("In_Type")
                .HasMaxLength(255);

            builder.Property(s => s.In_BatchCode)
                .HasColumnName("In_BatchCode")
                .HasMaxLength(255);

            builder.Property(s => s.Spec)
                .HasColumnName("Spec")
                .HasMaxLength(255);

            builder.Property(s => s.SiloCode)
                .HasColumnName("SiloCode")
                .HasMaxLength(255);

            builder.Property(s => s.SiloName)
                .HasColumnName("SiloName")
                .HasMaxLength(255);

            builder.Property(s => s.IsDeleted)
                .HasColumnName("IsDeleted");

            // 索引配置
            builder.HasIndex(s => s.MaterCode)
                .HasDatabaseName("IX_SM_Stock_In_MaterCode");

            builder.HasIndex(s => s.WarehouseID)
                .HasDatabaseName("IX_SM_Stock_In_WarehouseID");

            builder.HasIndex(s => s.SiloCode)
                .HasDatabaseName("IX_SM_Stock_In_SiloCode");

            // 软删除筛选器
        }
    }
}